Page({
  data: {
    name: "",
    numbers: ""
  },
  onLoad: function (options) {
    var that = this;
    var session3rd = wx.getStorageSync("session3rd");
    wx.request({
      url: "https://myzhongchou.net/public/index.php/api/user/getcard",
      data: {
        session3rd: session3rd
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        // console.log(res);
        that.setData({
          name: res.data.msg.actual_name,
          numbers: res.data.msg.card
        })
      }
    })
  },
  submit: function (e) {
    var submit = e.detail.value;
    var session3rd = wx.getStorageSync("session3rd");
    // console.log(submit);
    if (submit.name == "") {
      wx.showToast({
        title: '请填写你的名字',
        image: '../../img/gantan.png'
      })
      return false;
    }
    if (submit.number == "") {
      wx.showToast({
        title: '请填写你的证件号',
        image: '../../img/gantan.png'
      })
      return false;
    }
    wx.request({
      url: "https://myzhongchou.net/public/index.php/api/user/insert_card",
      data: {
        session3rd:session3rd,
        name: submit.name,
        card: submit.number
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        if (res.data.success == 0) {
          wx.showToast({
            title: res.data.msg,
            icon: 'success',
            duration:1500,
            success:function(){
              setTimeout(function(){
                wx.switchTab({
                  url: '../wode/wode'
                })
              },2000)
            }
          })
        
        } else if (res.data.error == 1) {
          wx.showToast({
            title: res.data.msg,
            image: '../../img/gantan.png'
          })
        } else if (res.data.error == 2) {
          wx.showToast({
            title: ' 信息已存在',
            image: '../../img/gantan.png'
          })
        } else {
          wx.showToast({
            title: '网络错误，请重试',
            image: '../../img/gantan.png'
          })
        }
      }
    })
  }
})